package com.xmg.p2p.base.util;

import com.xmg.p2p.base.domain.Logininfo;
import com.xmg.p2p.base.vo.VerifyCodeVo;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;

/**
 * lcd  2020/5/7
 * Description:
 */
public class UserContext {
    public static final String USER_IN_SESSION = "logininfo";
    public static final String VERIFY_CODE_IN_SESSION = "VERIFY_CODE_IN_SESSION";
    public static HttpSession session = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession();

    public static void setLogininfo(Logininfo logininfo) {
        session.setAttribute(USER_IN_SESSION, logininfo);
    }

    public static Logininfo getLogininfo() {
        return (Logininfo) session.getAttribute(USER_IN_SESSION);
    }

    public static void setVerifyCode(VerifyCodeVo verifyCodeVo) {
        session.setAttribute(VERIFY_CODE_IN_SESSION, verifyCodeVo);
    }

    public static VerifyCodeVo getVerifyCode() {
        return (VerifyCodeVo) session.getAttribute(VERIFY_CODE_IN_SESSION);
    }
}
